export const getURLArray = (pathName) => {
  let urlArray = pathName.split("/").slice(1);
  urlArray = urlArray.map((r, i) => "/" + urlArray.slice(0, i + 1).join("/"));
  return urlArray;
};
//递归匹配,sourceData为嵌套结构，matchData为平行结构,layer为开始匹配的层数
export const findPath = (sourceData, matchData, layer, callback) => {
  const matchRoute = sourceData.find((r) => r.key == matchData[layer]);
  if (matchRoute) {
    //找到对应key
    let end = false;

    if (matchData[layer + 1] && matchRoute.children) {
      //如果有下一层、下一个
      findPath(matchRoute.children, matchData, layer + 1);
    } else {
      // 没有下一层，下一个（终点）
      end = true;
    }
    if (callback) {
      callback(matchRoute, end);
    }
  } else {
    //没找到对应key
  }
};
